// pages/Result/Result.js
var startX, endX;
var moveFlag = true; // 判断执行滑动事件
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList: ['综合', '图片', '喂养', '疾病', '宠友圈'],
    left: '6%',
    cur: 0,
    show: 0,
  },
  touchStart: function (e) {
    startX = e.touches[0].pageX; // 获取触摸时的原点
    moveFlag = true;
  },
  // 触摸移动事件
  touchMove: function (e) {
    endX = e.touches[0].pageX; // 获取触摸时的原点
    if (moveFlag) {
      if (endX - startX > 50) {
        console.log("向左滑动");
        moveFlag = false;
        if (this.data.cur == 0) {
          console.log(1)
          return
        }
        let cur = --this.data.cur
        if (cur == 0) {
          this.setData({
            left: "6%",
            cur: cur,
            isShowDailog: false,
            show: 0
          })
        }
        if (cur == 1) {
          this.setData({
            left: "26%",
            cur: cur,
            isShowDailog: false,
            show: 1
          })
        }
        if (cur == 2) {
          this.setData({
            left: "46%",
            cur: cur,
            isShowDailog: false,
            show: 2
          })
        }
        if (cur == 3) {
          this.setData({
            left: "66%",
            cur: cur,
            isShowDailog: false,
            show: 3
          })
        }
        if (cur == 4) {
          this.setData({
            left: "86%",
            cur: cur,
            isShowDailog: false,
            show: 4
          })
        }

      }
      if (startX - endX > 50) {
        console.log("向右滑动");
        moveFlag = false;
        if (this.data.cur == 4) {
          return
        }
        let cur = ++this.data.cur
        if (cur == 0) {
          this.setData({
            left: "6%",
            cur: cur,
            isShowDailog: false,
            show: 0
          })
        }
        if (cur == 1) {
          this.setData({
            left: "26%",
            cur: cur,
            isShowDailog: false,
            show: 1
          })
        }
        if (cur == 2) {
          this.setData({
            left: "46%",
            cur: cur,
            isShowDailog: false,
            show: 2
          })
        }
        if (cur == 3) {
          this.setData({
            left: "66%",
            cur: cur,
            isShowDailog: false,
            show: 3
          })
        }
        if (cur == 4) {
          this.setData({
            left: "86%",
            cur: cur,
            isShowDailog: false,
            show: 4
          })
        }
      }
    }
  },
  // 触摸结束事件
  touchEnd: function (e) {
    moveFlag = true; // 回复滑动事件
  },
  tab(e) {
    console.log(e.currentTarget.dataset.index)
    var index = e.currentTarget.dataset.index
    if (index == 0) {
      this.setData({
        left: "6%",
        cur: index,
        show: 0
      })
    } else if (index == 1) {
      this.setData({
        left: "26%",
        cur: index,
        show: 1
      })

    } else if (index == 2) {
      this.setData({
        left: "46%",
        cur: index,
        show: 2
      })
    } else if (index == 3) {
      this.setData({
        left: "66%",
        cur: index,
        show: 3
      })
    } else {
      this.setData({
        left: "86%",
        cur: index,
        show: 4
      })
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})